package com.lab.webSocket.controller;

import com.lab.webSocket.webSocket.HandshakeInterceptor;
import com.lab.webSocket.webSocket.WebSocketEndPoint;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * Created by xu_jiaHui on 2017/8/26.
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(myhandler(), "/websocket").setAllowedOrigins("*");
        registry.addHandler(myhandler(), "/sockjs/websocket").withSockJS();
    }

    @Bean
    public WebSocketHandler myhandler() {
        return new WebSocketEndPoint();
    }

}
